package com.hxt.framework.utils;

import java.util.Random;

public class RandomUtil {
	// 生成n位随机数(字母大写或小写)
	public static String getCharAndNUM(int length) {
		String val = "";
		Random random = new Random();
		for (int i = 0; i < length; i++) {
			// 输出字母还是数字
			String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
			// 字符串
			if ("char".equalsIgnoreCase(charOrNum)) {
				// 取得大写字母还是小写字母
				int choice = random.nextInt(2) % 2 == 0 ? 65 : 97;
				val += (char) (choice + random.nextInt(26));
			} else if ("num".equalsIgnoreCase(charOrNum)) { // 数字
				val += String.valueOf(random.nextInt(10));
			}
		}
		return val;
	}

	// 生成n位随机数(字母大写)
	public static String getUppercaseAndnum(int length) {
		String val = "";
		Random random = new Random();
		for (int i = 0; i < length; i++) {
			// 输出字母还是数字
			String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
			// 字符串
			if ("char".equalsIgnoreCase(charOrNum)) {
				val += (char) (65 + random.nextInt(26));
			} else if ("num".equalsIgnoreCase(charOrNum)) { // 数字
				val += String.valueOf(random.nextInt(10));
			}
		}
		return val;
	}

	// 生成n位随机数(字母小写)
	public static String getLowercaseAndnum(int length) {
		String val = "";
		Random random = new Random();
		for (int i = 0; i < length; i++) {
			// 输出字母还是数字
			String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num";
			// 字符串
			if ("char".equalsIgnoreCase(charOrNum)) {
				val += (char) (97 + random.nextInt(26));
			} else if ("num".equalsIgnoreCase(charOrNum)) { // 数字
				val += String.valueOf(random.nextInt(10));
			}
		}
		return val;
	}

	final static char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
			'9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M',
			'N', 'P', 'R', 'S', 'T', 'U', 'W', 'X', 'Y', 'Z' };

	public static String numericToString(int i, int system) {
		long num = 0;
		if (i < 0) {
			num = ((long) 2 * 0x7fffffff) + i + 2;
		} else {
			num = i;
		}
		char[] buf = new char[32];
		int charPos = 32;
		while ((num / system) > 0) {
			buf[--charPos] = digits[(int) (num % system)];
			num /= system;
		}
		buf[--charPos] = digits[(int) (num % system)];
		return new String(buf, charPos, (32 - charPos));
	}

	public static void main(String[] args) throws InterruptedException {
		// 1442547499179000

		// Random random = new Random();
//		for (int i = 0; i < 10; i++) {
//			Thread.sleep(1000);
//			String microsecond = DateUtil.getTimestamp(32); // 秒
//			String inquirySn = "X" + microsecond
//					+ RandomUtil.getUppercaseAndnum(4) + "-1";
//			System.out.println(inquirySn);
//		}
//		for (int i = 0; i <1000; i++) {
			System.out.println(RandomUtil.getUppercaseAndnum(10));	
//		}

	}
	public static String getNum(int length){
		String val = "";
		//long q=Math.round(Math.random()) * 100000;
		Random random = new Random();
		for (int i = 0; i < length; i++) {
			
			int j=random.nextInt(10);
			if(i==0&&j==0){
				val+="1";
			}
			else{
				val += String.valueOf(j);	
			}
		}
		return val;
	}
}
